package net.randomice.emf.observables.demo.extlibrary.rcp;

import net.randomice.emf.observables.demo.extlibrary.rcp.editors.LibraryEditor;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IPersistableElement;
import org.eclipse.ui.IStartup;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;


public class Startup implements IStartup {

	public void earlyStartup() {
		final IWorkbench workbench = PlatformUI.getWorkbench();
		workbench.getDisplay().asyncExec(new Runnable() {
			public void run() {
				IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
				if (window != null) {
					try {
						window.getActivePage().openEditor(new IEditorInput() {

							@SuppressWarnings("unchecked")
							public Object getAdapter(Class arg0) {
								return null;
							}

							public String getToolTipText() {
								return "";
							}

							public IPersistableElement getPersistable() {
								return null;
							}

							public String getName() {
								return "";
							}

							public ImageDescriptor getImageDescriptor() {
								return null;
							}

							public boolean exists() {
								return false;
							}
						}, LibraryEditor.class.getName());
					} catch (PartInitException e) {
						e.printStackTrace();
					}
				}
			}
		});
	}

}
